package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.mall.MallPlatform;
import com.tencreat.service.mall.IMallPlatformService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 关于我们信息Controller
 *
 * @author tencreat
 * @date 2021-11-13
 */
@Api(tags="关于我们信息api")
@RestController
@RequestMapping("/mall/platform")
public class AdminMallPlatformController extends BaseController {
    @Autowired
    private IMallPlatformService mallPlatformService;

    /**
     * 查询关于我们信息列表
     */
    @ApiOperation(value="查询关于我们信息列表")
    @PreAuthorize("@ss.hasPermi('mall:platform:list')")
    @PostMapping("/list")
    public HttpResult<IPage<MallPlatform>> list(@RequestBody  MallPlatform mallPlatform) {
        QueryWrapper<MallPlatform> wrapper = Wrappers.query(mallPlatform);
        Page<MallPlatform> page =  new Page<>(mallPlatform.getPageNum(), mallPlatform.getPageSize());
        return HttpResult.ok(mallPlatformService.page(page, wrapper));
    }

    /**
     * 导出关于我们信息列表
     */
    @ApiOperation(value="导出关于我们信息列表")
    @PreAuthorize("@ss.hasPermi('mall:platform:export')")
    @Log(title = "关于我们信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MallPlatform mallPlatform) {
        List<MallPlatform> list = mallPlatformService.selectMallPlatformList(mallPlatform);
        ExcelUtil<MallPlatform> util = new ExcelUtil<MallPlatform>(MallPlatform.class);
        return util.exportExcel(list, "platform");
    }

    /**
     * 获取关于我们信息详细信息
     */
    @ApiOperation(value="获取关于我们信息详细信息")
    @PreAuthorize("@ss.hasPermi('mall:platform:getInfo')")
    @PostMapping(value = "/getInfo")
    public HttpResult<MallPlatform> getInfo() {
        return HttpResult.ok(mallPlatformService.selectMallPlatformById());
    }

    /**
     * 新增关于我们信息
     */
    @ApiOperation(value="新增关于我们信息")
    @PreAuthorize("@ss.hasPermi('mall:platform:add')")
    @Log(title = "关于我们信息", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  MallPlatform mallPlatform) {
        return to(mallPlatformService.insertMallPlatform(mallPlatform));
    }

    /**
     * 修改关于我们信息
     */
    @ApiOperation(value="修改关于我们信息")
    @PreAuthorize("@ss.hasPermi('mall:platform:edit')")
    @Log(title = "商城管理>关于我们", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  MallPlatform mallPlatform) {
        return to(mallPlatformService.updateMallPlatform(mallPlatform));
    }

    /**
     * 删除关于我们信息
     */
    @ApiOperation(value="删除关于我们信息")
    @PreAuthorize("@ss.hasPermi('mall:platform:remove')")
    @Log(title = "关于我们信息", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody  ReqIdsParam ids) {
        return to(mallPlatformService.deleteMallPlatformByIds(ids));
    }
}
